package spike.jdbc.hello;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class MainInsert {

	public static void main(String[] args) throws Exception {
		System.out.println("loading driver");
		Class.forName("org.hsqldb.jdbcDriver");

		System.out.println("connecting");
		Connection vConnection = DriverManager.getConnection(
				"jdbc:hsqldb:hsql://localhost/", "sa", "");

		System.out.println("insert");
		Statement statement = vConnection.createStatement();

		// On simule des valeurs provenant d'une saisie utilisateur
		String vNom = "Rolling Stones";

		String vSql = "INSERT INTO titre  (id, artiste, album, nom) values (3, '"
				+ vNom + "', 'Sticky Fingers', 'Angie')";
		int vNbRecordTouched = statement.executeUpdate(vSql);

		System.out.println("inserted " + vNbRecordTouched + " records");

		statement.close();
		vConnection.close();

		System.out.println("done");
	}

}
